package com.zzyl.nursing.controller;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.NursingPlanDto;
import com.zzyl.nursing.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingPlan;
import com.zzyl.nursing.service.INursingPlanService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理计划控制器
 */
@Api(tags = "护理计划管理")
@RestController
@RequestMapping("/nursing/nursingPlan")
public class NursingPlanController extends BaseController {

    @Autowired
    private INursingPlanService nursingPlanService;

    @ApiOperation("查询所有护理计划")
    @GetMapping("/all")
    public AjaxResult listAll() {
        List<NursingPlan> list = nursingPlanService.listAll();
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('nursing:nursingPlan:list')")
    @ApiOperation("查询护理计划列表")
    @GetMapping("/list")
    public TableDataInfo<List<NursingPlan>> list(@ApiParam("护理计划查询条件") NursingPlan nursingPlan) {
        startPage();
        List<NursingPlan> list = nursingPlanService.selectNursingPlanList(nursingPlan);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('nursing:nursingPlan:query')")
    @ApiOperation("获取护理计划详细信息")
    @GetMapping(value = "/{id}")
    public R<NursingPlanVo> getInfo(@ApiParam("护理计划ID") @PathVariable("id") Long id) {
        NursingPlanVo nursingPlan = nursingPlanService.selectNursingPlanById(id);
        return R.ok(nursingPlan);
    }

    @PreAuthorize("@ss.hasPermi('nursing:nursingPlan:add')")
    @Log(title = "护理计划", businessType = BusinessType.INSERT)
    @ApiOperation("新增护理计划")
    @PostMapping
    public AjaxResult add(@ApiParam("护理计划对象") @RequestBody NursingPlanDto nursingPlanDto) {
        return toAjax(nursingPlanService.insertNursingPlan(nursingPlanDto));
    }

    @PreAuthorize("@ss.hasPermi('nursing:nursingPlan:edit')")
    @Log(title = "护理计划", businessType = BusinessType.UPDATE)
    @ApiOperation("修改护理计划")
    @PutMapping
    public AjaxResult edit(@ApiParam("护理计划对象") @RequestBody NursingPlanDto nursingPlanDto) {
        return toAjax(nursingPlanService.updateNursingPlan(nursingPlanDto));
    }

    @PreAuthorize("@ss.hasPermi('nursing:nursingPlan:remove')")
    @Log(title = "护理计划", businessType = BusinessType.DELETE)
    @ApiOperation("删除护理计划")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@ApiParam("护理计划ID") @PathVariable Long id) {
        return toAjax(nursingPlanService.deleteNursingPlanById(id));
    }
}